@echo off
setlocal enabledelayedexpansion

echo.
echo Creating AICoder project structure...
echo.

:: Create root directory
mkdir aicoder
cd aicoder

:: Create protos directory
mkdir protos
cd protos
echo syntax = "proto3"; > common.proto
echo syntax = "proto3"; > ai.proto
echo syntax = "proto3"; > git.proto
echo syntax = "proto3"; > task.proto
echo syntax = "proto3"; > logger.proto
echo syntax = "proto3"; > notification.proto
echo syntax = "proto3"; > prompt_optimizer.proto
cd ..

:: Create services directory
mkdir services
cd services

:: API Gateway Service
mkdir api-gateway
cd api-gateway
mkdir app
cd app
mkdir config
cd config
echo # Settings configuration > settings.py
echo # Constants > constants.py
cd ..
mkdir routers
cd routers
echo # AI router > ai.py
echo # Git router > git.py
echo # Task router > task.py
echo # Config router > config.py
cd ..
mkdir middlewares
cd middlewares
echo # Authentication middleware > auth.py
echo # Rate limiter middleware > rate_limit.py
echo # Logging middleware > logging.py
cd ..
mkdir services
cd services
echo # Core service > core.py
echo # Dependency service > dependency.py
cd ..
echo print("API Gateway") > main.py
cd ..
echo fastapi > requirements.txt
echo uvicorn >> requirements.txt
echo FROM python:3.11-slim > Dockerfile
echo WORKDIR /app >> Dockerfile
echo COPY . . >> Dockerfile
echo RUN pip install -r requirements.txt >> Dockerfile
echo CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"] >> Dockerfile
cd ..

:: Config Service
mkdir config-service
cd config-service
mkdir app
cd app
echo print("Config Service") > main.py
mkdir core
cd core
echo # Config loader > config_loader.py
echo # Config manager > config_manager.py
cd ..
mkdir db
cd db
echo # Database models > models.py
mkdir crud
cd crud
echo # Git config CRUD > git_config.py
echo # AI config CRUD > ai_config.py
echo # Task config CRUD > task_config.py
cd ..
mkdir migrations
cd migrations
echo # Migration files > __init__.py
cd ..
cd ..
mkdir api
cd api
mkdir v1
cd v1
echo # API endpoints > endpoints.py
echo # API schemas > schemas.py
cd ..
cd ..
cd ..
echo fastapi > requirements.txt
echo sqlalchemy >> requirements.txt
echo FROM python:3.11-slim > Dockerfile
echo WORKDIR /app >> Dockerfile
echo COPY . . >> Dockerfile
echo RUN pip install -r requirements.txt >> Dockerfile
echo CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"] >> Dockerfile
cd ..

:: AI Service
mkdir ai-service
cd ai-service
mkdir app
cd app
echo print("AI Service") > main.py
mkdir adapters
cd adapters
echo # DeepSeek adapter > deepseek.py
echo # Claude adapter > claude.py
echo # Base adapter > base_adapter.py
cd ..
mkdir services
cd services
mkdir codegen
cd codegen
echo # Code generation core > core.py
mkdir languages
cd languages
echo # Python code generator > python.py
echo # Java code generator > java.py
echo # Go code generator > go.py
cd ..
cd ..
mkdir review
cd review
echo # Code review core > core.py
mkdir rules
cd rules
echo # Review rules > __init__.py
cd ..
cd ..
mkdir arch
cd arch
echo # Architecture core > core.py
mkdir diagrams
cd diagrams
echo # Diagram generators > __init__.py
cd ..
cd ..
cd ..
mkdir utils
cd utils
mkdir prompt
cd prompt
echo # Prompt builder > builder.py
mkdir templates
cd templates
echo # Prompt templates > __init__.py
cd ..
cd ..
mkdir validation
cd validation
echo # Code validator > code_validator.py
echo # Security scanner > security.py
cd ..
cd ..
cd ..
mkdir scripts
cd scripts
echo # Model testing script > model_test.py
cd ..
cd ..
echo fastapi > requirements.txt
echo requests >> requirements.txt
echo FROM python:3.11-slim > Dockerfile
echo WORKDIR /app >> Dockerfile
echo COPY . . >> Dockerfile
echo RUN pip install -r requirements.txt >> Dockerfile
echo CMD ["python", "app/main.py"] >> Dockerfile
cd ..

:: Prompt Optimizer Service
mkdir prompt-optimizer-service
cd prompt-optimizer-service
mkdir app
cd app
echo print("Prompt Optimizer Service") > main.py
mkdir core
cd core
echo # Evaluator > evaluator.py
echo # Optimizer > optimizer.py
echo # Monitor > monitor.py
echo # AB Tester > ab_tester.py
cd ..
mkdir db
cd db
echo # Database models > models.py
echo # CRUD operations > crud.py
cd ..
mkdir api
cd api
echo # API routes > routes.py
echo # API schemas > schemas.py
cd ..
echo # Configuration > config.py
cd ..
echo fastapi > requirements.txt
echo numpy >> requirements.txt
echo pandas >> requirements.txt
echo FROM python:3.11-slim > Dockerfile
echo WORKDIR /app >> Dockerfile
echo COPY . . >> Dockerfile
echo RUN pip install -r requirements.txt >> Dockerfile
echo CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"] >> Dockerfile
cd ..

:: Git Service
mkdir git-service
cd git-service
mkdir cmd
cd cmd
echo package main > main.go
echo.
echo import "fmt"
echo.
echo func main() {
echo     fmt.Println("Git Service")
echo }
cd ..
mkdir internal
cd internal
mkdir api
cd api
mkdir handlers
cd handlers
echo // Branch handler > branch.go
echo // Commit handler > commit.go
echo // Repo handler > repo.go
cd ..
mkdir middleware
cd middleware
echo // Middleware > __init__.go
cd ..
cd ..
mkdir core
cd core
mkdir operations
cd operations
echo // Clone operation > clone.go
echo // Branch operation > branch.go
echo // Commit operation > commit.go
cd ..
mkdir security
cd security
echo // Security policy > policy.go
echo // Security scanner > scanner.go
cd ..
cd ..
mkdir storage
cd storage
echo // Repo storage > repo_store.go
mkdir cache
cd cache
echo // Cache implementation > __init__.go
cd ..
cd ..
mkdir models
cd models
echo // Data models > __init__.go
cd ..
mkdir utils
cd utils
echo // Utility functions > __init__.go
cd ..
cd ..
echo module aicoder/git-service > go.mod
echo go 1.20 >> go.mod
echo FROM golang:1.20-alpine > Dockerfile
echo WORKDIR /app >> Dockerfile
echo COPY . . >> Dockerfile
echo RUN go mod tidy >> Dockerfile
echo RUN go build -o main ./cmd >> Dockerfile
echo CMD ["./main"] >> Dockerfile
cd ..

:: Task Service
mkdir task-service
cd task-service
mkdir cmd
cd cmd
echo package main > main.go
echo.
echo import "fmt"
echo.
echo func main() {
echo     fmt.Println("Task Service")
echo }
cd ..
mkdir internal
cd internal
mkdir api
cd api
mkdir handlers
cd handlers
echo // Task handlers > __init__.go
cd ..
cd ..
mkdir core
cd core
mkdir scheduler
cd scheduler
echo // Manager > manager.go
echo // Cron scheduler > cron.go
echo // Task queue > queue.go
cd ..
mkdir tasks
cd tasks
echo // Scan task > scan_task.go
echo // Fix task > fix_task.go
echo // Feature task > feature_task.go
cd ..
cd ..
mkdir storage
cd storage
echo // Task storage > task_store.go
cd ..
mkdir models
cd models
echo // Data models > __init__.go
cd ..
cd ..
echo module aicoder/task-service > go.mod
echo go 1.20 >> go.mod
echo FROM golang:1.20-alpine > Dockerfile
echo WORKDIR /app >> Dockerfile
echo COPY . . >> Dockerfile
echo RUN go mod tidy >> Dockerfile
echo RUN go build -o main ./cmd >> Dockerfile
echo CMD ["./main"] >> Dockerfile
cd ..

:: Logger Service
mkdir logger-service
cd logger-service
mkdir src
cd src
echo fn main() { > main.rs
echo     println!("Logger Service"); >> main.rs
echo } >> main.rs
mkdir api
cd api
echo // gRPC server > grpc_server.rs
mkdir handlers
cd handlers
echo // Handlers > __init__.rs
cd ..
cd ..
mkdir core
cd core
echo // Log processor > processor.rs
echo // Log transformer > transformer.rs
echo // Log analyzer > analyzer.rs
cd ..
mkdir storage
cd storage
echo // Elastic storage > elastic.rs
echo // Archive storage > archive.rs
cd ..
mkdir utils
cd utils
echo // Time utilities > time.rs
cd ..
cd ..
echo [package] > Cargo.toml
echo name = "logger-service" >> Cargo.toml
echo version = "0.1.0" >> Cargo.toml
echo edition = "2021" >> Cargo.toml
echo. >> Cargo.toml
echo [dependencies] >> Cargo.toml
echo tokio = { version = "1", features = ["full"] } >> Cargo.toml
echo tonic = "0.10" >> Cargo.toml
echo FROM rust:1.70-slim > Dockerfile
echo WORKDIR /app >> Dockerfile
echo COPY . . >> Dockerfile
echo RUN cargo build --release >> Dockerfile
echo CMD ["./target/release/logger-service"] >> Dockerfile
cd ..

:: Notification Service
mkdir notification-service
cd notification-service
mkdir src
cd src
echo fn main() { > main.rs
echo     println!("Notification Service"); >> main.rs
echo } >> main.rs
mkdir api
cd api
echo // gRPC server > grpc_server.rs
mkdir handlers
cd handlers
echo // Handlers > __init__.rs
cd ..
cd ..
mkdir core
cd core
echo // Notifier > notifier.rs
mkdir channels
cd channels
echo // Email channel > email.rs
echo // SMS channel > sms.rs
echo // App push channel > app_push.rs
cd ..
echo // Approval process > approval.rs
cd ..
mkdir templates
cd templates
echo // Template manager > manager.rs
mkdir default_templates
cd default_templates
echo // Default templates > __init__.rs
cd ..
cd ..
mkdir storage
cd storage
echo // History storage > history_store.rs
cd ..
cd ..
echo [package] > Cargo.toml
echo name = "notification-service" >> Cargo.toml
echo version = "0.1.0" >> Cargo.toml
echo edition = "2021" >> Cargo.toml
echo. >> Cargo.toml
echo [dependencies] >> Cargo.toml
echo tokio = { version = "1", features = ["full"] } >> Cargo.toml
echo tonic = "0.10" >> Cargo.toml
echo FROM rust:1.70-slim > Dockerfile
echo WORKDIR /app >> Dockerfile
echo COPY . . >> Dockerfile
echo RUN cargo build --release >> Dockerfile
echo CMD ["./target/release/notification-service"] >> Dockerfile
cd ..

:: Go back to root
cd ..\..\

:: Create deploy directory
mkdir deploy
cd deploy
mkdir docker
cd docker
echo version: '3.8' > docker-compose.yml
echo services: >> docker-compose.yml
echo "  api-gateway:" >> docker-compose.yml
echo "    build: ../services/api-gateway" >> docker-compose.yml
echo "    ports:" >> docker-compose.yml
echo "      - \"8000:8000\"" >> docker-compose.yml
mkdir production
mkdir dev
cd ..
mkdir k8s
cd k8s
mkdir base
cd base
echo # Namespace > namespace.yaml
echo # Configs > configs.yaml
cd ..
mkdir services
cd services
mkdir api-gateway
cd api-gateway
echo # Deployment > deployment.yaml
echo # Service > service.yaml
cd ..\..\..
mkdir overlays
cd overlays
mkdir production
mkdir staging
cd ..\..
mkdir systemd
cd systemd
echo [Unit] > api-gateway.service
echo Description=AICoder API Gateway Service >> api-gateway.service
echo After=network.target >> api-gateway.service
echo. >> api-gateway.service
echo [Service] >> api-gateway.service
echo Type=simple >> api-gateway.service
echo User=aicoder >> api-gateway.service
echo WorkingDirectory=/opt/aicoder/api-gateway >> api-gateway.service
echo ExecStart=/usr/bin/python app/main.py >> api-gateway.service
echo Restart=always >> api-gateway.service
echo RestartSec=10 >> api-gateway.service
echo. >> api-gateway.service
echo [Install] >> api-gateway.service
echo WantedBy=multi-user.target >> api-gateway.service
cd ..
mkdir terraform
cd terraform
mkdir modules
cd modules
mkdir network
mkdir database
mkdir compute
cd ..
mkdir environments
cd environments
mkdir production
mkdir staging
cd ..\..\..\..

:: Create scripts directory
mkdir scripts
cd scripts
mkdir setup
cd setup
echo @echo off > install_dependencies.bat
echo echo Installing dependencies... >> install_dependencies.bat
cd ..
mkdir migration
cd migration
echo @echo off > run_migrations.bat
echo echo Running migrations... >> run_migrations.bat
cd ..
mkdir backup
cd backup
echo @echo off > daily_backup.bat
echo echo Performing daily backup... >> daily_backup.bat
cd ..
mkdir monitoring
cd monitoring
echo @echo off > health_check.bat
echo echo Performing health check... >> health_check.bat
cd ..\..\..

:: Create docs directory
mkdir docs
cd docs
mkdir architecture
cd architecture
echo # System Architecture > system_arch.md
echo # Data Flow > data_flow.md
echo # Deployment Architecture > deployment.md
cd ..
mkdir api
cd api
echo # OpenAPI Specification > openapi.yaml
mkdir examples
cd examples
echo # API Examples > __init__.md
cd ..
cd ..
mkdir development
cd development
echo # Coding Standards > coding_standards.md
echo # Testing Guide > testing_guide.md
echo # Contribution Guidelines > contribution.md
cd ..
mkdir operations
cd operations
echo # Deployment Guide > deployment_guide.md
echo # Monitoring Guide > monitoring.md
echo # Troubleshooting Guide > troubleshooting.md
cd ..
mkdir user_guide
cd user_guide
echo # Getting Started > getting_started.md
echo # Best Practices > best_practices.md
cd ..\..\..

:: Create tests directory
mkdir tests
cd tests
mkdir e2e
mkdir load
mkdir security
mkdir data
cd ..

:: Create .github directory
mkdir .github
cd .github
mkdir workflows
cd workflows
echo name: CI > ci.yml
echo on: [push] >> ci.yml
echo jobs: >> ci.yml
echo "  build:" >> ci.yml
echo "    runs-on: ubuntu-latest" >> ci.yml
echo name: CD > cd.yml
echo name: Security Scan > security-scan.yml
cd ..
mkdir ISSUE_TEMPLATE
mkdir PULL_REQUEST_TEMPLATE
cd ..

:: Create root files
echo # AICoder Project > README.md
echo MIT License > LICENSE

echo.
echo Project structure created successfully!
echo Location: %CD%
echo.
echo Next steps:
echo 1. Install Docker and Docker Compose
echo 2. Run in deploy\docker: docker-compose up
echo 3. Open http://localhost:8000 to verify API gateway
echo.
pause